package com.itheima.demo003;

import java.util.ArrayList;

public class test34 {
    public static void main(String[] args) {
        //需求:定义一个集合,添加一些学生对象,并进行遍历
        //学生类的属性为:姓名,年龄

        //1.定义一个集合
        ArrayList<Student> list = new ArrayList<>();

        //2.创建学生对象
        Student s1 = new Student("zhangsan",16);
        Student s2 = new Student("lisi",17);
        Student s3 = new Student("wangwu",18);
        Student s4 = new Student("zhaoliu",19);
        Student s5 = new Student("xiaoqi",20);

        //3.添加元素
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);
        
        //4.遍历
        for (int i = 0; i < list.size(); i++) {
            //i 索引 list.get(i) 元素/学生对象
            Student stu = list.get(i);
            System.out.println(stu.getName() + ", " + stu.getAge());
        }
    }
}
